﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace DDOS.Objects.Enemies
{
    class Enemy0 : Enemy
    {
        private Vector2 patrol_point;
        private Vector2 origin;
        Rectangle spriteRectangle;
        private const Decimal SPEED = 1m;
        Random ran;
        bool on_patrol;

        public override void InitializeComponents()
        {
            this.health = 10;
            this.power = 0;
            this.speed = 0;
            this.sight = 0;
            on_patrol = true;
            this.origin = new Vector2(this.coordinates.X, this.coordinates.Y);
            this.patrol_point = new Vector2(origin.X + ran.Next(-50, 50), origin.Y + ran.Next(50, 50));
            this.texture = ImageManager2D.Instance.Placeholder2;
            bounding_object = new BoundingRectangle((int)coordinates.X, (int)coordinates.Y, (int)coordinates.X + 25, (int)coordinates.Y + 25);
            spriteRectangle = new Rectangle((int)coordinates.X, (int)coordinates.Y, 25, 25);
            this.velocity = new Vector2(0, 0);
            blocked = false;
        }

        public void init_random(Random r)
        {
            ran = r;
        }

        private void patrol()
        {
            if ((this.coordinates - patrol_point).Length() >= (float)SPEED)
            {
                Vector2 v = (patrol_point - this.coordinates);
                v.Normalize();
                coordinates += v*(float)SPEED;
            }
            else
            {
                this.patrol_point = new Vector2(origin.X + ran.Next(-50, 50), origin.Y + ran.Next(-50, 50));
            }
        }

        private void act()
        {

        }

        public override void Update(GameTime game_Time)
        {
            if (on_patrol)
            {
                patrol();
            }
            act();
            this.bounding_object.Move(this.coordinates.X, this.coordinates.Y);
            this.spriteRectangle.X = (int)this.coordinates.X;
            this.spriteRectangle.Y = (int)this.coordinates.Y;
        }

        public override void Draw()
        {
            ScreenManager.Instance.CurrentSpriteBatch.Draw(texture, spriteRectangle, Color.White);
        }

    }
}
